<!DOCTYPE html>
<html lang="en">
<title>个人储值卡退款</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<style>
    .ibox-footer h4 span {
        margin-right: 25px
    }
</style>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">个人储值卡退款</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline"  action="to_recharge_list" role="form" id="form" method="get" accept-charset="UTF-8">
                            <div class="form-group">
                                <label for="storeName">充值时间：</label>
                                <div class="input-group date">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="text" class="form-control" id="createTime" name="createTime" value="${createTime!}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label>充值方式：</label>
                                <select class="form-control" id="rechargeType" name="rechargeType">
                                	<#if rechargeType??>
	                                    <option value="0" <#if rechargeType=0 > selected="selected"</#if> >全部</option>
	                                    <option value="1" <#if rechargeType=1 > selected="selected"</#if> >在线支付</option>
	                                    <option value="2" <#if rechargeType=2 > selected="selected"</#if>>兑换码</option>
                                    </#if>
                                </select>
                            </div>
                            <input type="hidden" id="pageNo" value="${pageNo!}" name="pageNo">
                            <input type="hidden" id="userId" name="userId" value="${userId!}">
                            <input type="hidden" id="payStatus" name="payStatus" value="1">
                            <input type="hidden" id="rechargeType" name="rechargeType" value="1">
                            <button type="submit" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr style="width: 100%">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th>充值方式</th>
                                <th>充值金额</th>
                                <th>实到金额</th>
                                <th>订单号</th>
                                <th>充值时间</th>
                                <#if sys_userInfo??>
                                 <th>退款</th>
                                </#if>
                               
                            </tr>
                            </thead>
                            <tbody>
                            <#if list??> <#list list as list>
								<tr>
									<td>${list_index + 1}</td>
									<td>${list.rechargeType!}</td>
									<td>${list.faceAmt!}</td>
									<td>${list.actualAmt!}</td>
									<td>${list.changeCode!}</td>
									<td>${list.createTime?datetime}</td>
									<#if sys_userInfo??>
                                 	<td>
                                 		<#if (list_index + 1) == 1 && refunAmt?? && refunAmt != 0>
	                                 		<div class="input-group">
									            <span class="input-group-addon">$</span>
									            <input type="number" class="form-control" name="user_refund" id="user_refund${list_index + 1}">
									        </div>
									        <div class="input-group">
									             <textarea rows="" cols="" id="remark" placeholder="退款备注必填" ></textarea>
									        </div>
	                                 		<!-- <input type="number" name="user_refund" id="user_refund${list_index + 1}"/> -->
	                                 		<button type="button" class="btn btn-danger" onclick="amt_refund('${list.changeCode!}','user_refund${list_index + 1}','${list.id!}','${list.faceAmt}')"><i class="fa fa-minus-sign"></i> 退款</button>
                                 		</#if>
                                 	</td>
                                	</#if>
								</tr>
								</#list> 
								</#if>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">
                        用户ID：<span>${NO!}</span>
                        用户昵称：<span>${userName!}</span>
                        当前余额：<span>¥${userAccount!}</span>
                        合计充值：<span>¥${userAmount!'0'}</span>
                        可退金额：<span >¥${refunAmt!'0'}</span>   
                        <input type="hidden" id="tukuan" name="tukuan" value="${refunAmt!'0'}">           
                    </h4>
                    <div id="copot-page" class="pull-right"></div>
                </div>
                <div class="">
                	<a href="${baseUrl}system/custom/to_custom_list"><button class="btn btn-outline btn-primary">返回列表页</button></a>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${baseUrl}js/main.js"></script>
<script>
    $(document).ready(function () {
        $('.input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            //calendarWeeks: true,
            autoclose: true,
            format: 'yyyy-mm-dd',
        });
        //导出excel
        ExampleFile("用户excel");
        $("#createTime").click(function(){
        	$("#pageNo").val(1);
        });
        //分页
        new Page({
            parent: $("#copot-page"),
            nowPage: ${pageNo!},
            pageSize: 10,
            totalCount: ${pageAccount!},
            setting: {
                defaultPage: 7,//默认显示可点击分页的个数
                firstPageText: "首页",
                prevPageText: "上一页",
                nextPageText: "下一页",
                lastPageText: "尾页"
            },
            callback: function (nowPage, totalPage) {
               /*  alert("当前" + nowPage + "页--总共有" + totalPage + "页") */
            	$("#pageNo").val(nowPage);
           	 	$("#form").submit();
            }
        });
        $("#remark").click(function(){
        	$("#remark").css("border","solid 1px #d6d2d2");
        });
        
    });
    // 
    function amt_refund(order_number,refund_id,id,face_amt){
    	var refund_amt = $("#"+refund_id).val();
    	var tukuan = $("#tukuan").val();
    	var remark = $("#remark").val();
    	var html = '<p>操作退款前请确认以下几点：</p>'+
    			   '<p>1、用户是退款部分代金卡订单，还是全部代金卡订单;</p>'+
    			   '<p>2、公司退款账户内余额是否充足;</p>'+
    			   '<p>3、用户当前是否有使用代金卡支付的状态为进行中的订单，如果有请与用户确认是否取消后再退款;</p>'+
    			   '<p>4、操作退款时，请仔细填写备注信息（退款原因，是否有进行中的订单等信息），方便后续排查;</p>';
    			   
    	if(parseFloat(refund_amt) > parseFloat(face_amt)){
    		swal("退款失败!", "输入的退款金额不能大于实际的充值金额", "error");
    		return false;
    	}
    	if(parseFloat(refund_amt) > parseFloat(tukuan)){
    		swal("退款失败!", "输入的退款金额不能大于可退款金额", "error");
    		return false;
    	}
    	if(isNaN(refund_amt)){
    		swal("退款失败!", "请输入正确的数字", "error");
    		return false;
    	}
    	if(refund_amt.length < 1){
    		swal("退款失败!", "退款金额不能为空", "error");
    		return false;
    	}
    	if(refund_amt < 0.01){
    		swal("退款失败!", "退款金额不能小于0.01", "error");
    		return false;
    	}
    	if(remark.length < 1){
    		var remarks = $("#remark"); 
    		$("#remark").css("border","solid 1px red");
    		swal("退款失败!", "退款备注必须填写以便日后追踪记录", "error");
    		return false;
    	}
    	swal({
            title: "确定退款金额为："+refund_amt,
            text: html,
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "确定!",
        }).then(function () {
            $.ajax({
                url: "card_refund",              // 请求地址
                data: {
                    "order_number": order_number,
                    "biaoshi": 1,
                    "amt":refund_amt,
                    "consume_id":id,
                    "remark":remark
                },
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                	if(data.ret == 0){
                    	swal("退款成功!", "您已退款成功,金额将打入对方账户", "success");
                    	//分页
                    	$("#form").submit();
                    }else{
                    	swal("退款失败!", data.msg, "error");
                    }
                },
                error: function () {
                    swal("退款失败!", "请联系管理员处理", "error");
                }
            });

        }, function () {
    	});
    }
</script>
</@body.page>
</html>